# coding=utf-8
# !/usr/bin/python
import json
import time

import requests
from base.spider import Spider
import sys

sys.path.append('..')
kurl = "http://sspa8.top:9992"
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0',
}

class Spider(Spider):
    global xurl
    global headerx
    global pm

    def getName(self):
        return "首页"

    def init(self, extend):
        pass

    def isVideoFormat(self, url):
        pass

    def manualVideoCheck(self):
        pass

    def homeVideoContent(self):
        res = requests.get(f'{kurl}/homeVideos').json()
        return res

    def homeContent(self, filter):
        res = requests.get(f'{kurl}/home').json()
        return res

    def categoryContent(self, cid, pg, filter, ext):
        res = requests.get(f'{kurl}/category?cid={cid}&pg={pg}').json()
        return res

    def detailContent(self, ids, pg=1):
        did = ids[0]
        res = requests.get(f'{kurl}/detail?ids={did}').json()
        return res

    def playerContent(self, flag, id, vipFlags):
        url = "http://sspa8.top:8100/suisui.php?url=" + id
        res = requests.get(url=url, headers=headers)
        res.encoding = "utf-8"
        kjson = res.json()
        url = kjson['url']
        result = {}
        result["parse"] = 0
        result["playUrl"] = ''
        result["url"] = url
        return result

    def searchContentPage(self, key, quick, page):
        res = requests.get(f'{kurl}/search?key={key}&page={page}').json()
        return res

    def searchContent(self, key, quick, pg="1"):
        return self.searchContentPage(key, quick, '1')


    def localProxy(self, params):
        if params['type'] == "m3u8":
            return self.proxyM3u8(params)
        elif params['type'] == "media":
            return self.proxyMedia(params)
        elif params['type'] == "ts":
            return self.proxyTs(params)
        return None